package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.CustomerBean;
import com.project.mapper.ICustomerMapper;
import com.project.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    private ICustomerMapper mapper;
    @Override
    public Page<CustomerBean> findByItem(Integer pageNo, String name, String ranges) {
        QueryWrapper<CustomerBean> qw = new QueryWrapper<>();
        if (name!=null&&name.length()!=0){
            qw.like("c_name",name);
        }
        if (ranges!=null&& ranges.length()!=0){
            qw.like("c_range",ranges);
        }

        return mapper.selectPage(new Page(pageNo,5),qw) ;
    }

    @Override
    public CustomerBean findById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public void update(Integer id, String cadre, String phone, String ranges) {
            CustomerBean customerBean = new CustomerBean();
            customerBean.setId(id);
            customerBean.setCadre(cadre);
            customerBean.setPhone(phone);
            customerBean.setRange(ranges);
            mapper.updateById(customerBean);
    }

    @Override
    public void add(CustomerBean customer) {
           mapper.insert(customer);
    }

    @Override
    public List<CustomerBean> findAll() {
        return mapper.selectList(null);
    }
}
